﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Catsland.Core
{
	public class UniqueList<typename>
	{
		public Dictionary<String, typename> m_list;

		public virtual void AddItem(String key, typename value)
		{
			if (m_list == null)
			{
				m_list = new Dictionary<String, typename>();
			}
			if (!m_list.ContainsKey(key))
			{
				m_list.Add(key, value);
			}
#if DEBUG
			else
			{
				Console.WriteLine("Warning! Repeat insert in UniqueList. Key: " + key);
			}
#endif
		}

		public virtual typename GetItem(String key)
		{
			if (m_list == null || !m_list.ContainsKey(key))
			{
				return default(typename);
			}
			return m_list[key];
		}

        public virtual bool ContainKey(string key)
        {
            if (m_list == null)
            {
                return false;
            }
            if (m_list.ContainsKey(key))
            {
                return true;
            }
            return false;
        }

		public virtual void ReleaseAll()
		{
			if (m_list != null)
			{
				m_list.Clear();
			}
		}

        public virtual void RemoveItem(string key)
        {
            if (m_list != null && m_list.ContainsKey(key))
            {
                m_list.Remove(key);
            }
        }

		public Dictionary<String, typename> GetList()
		{
			return m_list;
		}
	}
}
